package com.bys.exception;

import com.bys.vo.ErrorCode;

import static com.bys.util.ServiceExceptionUtil.doFormat;

public class ServiceException  extends RuntimeException{
    private static final long serialVersionUID = 1L;
    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误提示
     */
    private String message;
    /**
     * 空构造方法，避免反序列化问题
     */
    public ServiceException()
    {
    }


    public ServiceException( String message)
    {
        this.message = message;
    }
    public ServiceException(String message, Integer code)
    {
        this.message = message;
        this.code = code;
    }

    public ServiceException(ErrorCode errorCode,Object... params) {
        String message = doFormat(errorCode.getCode(), errorCode.getMessage(), params);
        this.code = errorCode.getCode();
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public ServiceException setCode(Integer code) {
        this.code = code;
        return this;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public ServiceException setMessage(String message) {
        this.message = message;
        return this;
    }
}
